<?php

namespace Kunfeng\Dify\Event;

/**
 * 基础事件类
 */
abstract class BaseEvent
{
    protected $event;
    protected $data;

    public function __construct(string $event, array $data = [])
    {
        $this->event = $event;
        $this->data = $data;
    }

    public function getEvent(): string
    {
        return $this->event;
    }

    public function getData(): array
    {
        return $this->data;
    }

    public function toArray(): array
    {
        return [
            'event' => $this->event,
            'data' => $this->data,
        ];
    }

    /**
     * 从数组创建事件（子类需要重写）
     */
    public static function fromArray(array $data)
    {
        throw new \BadMethodCallException('fromArray method must be implemented in child class');
    }
}
